package cn.threewaters.qtyy.web.controller.business;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.plugins.Page;

import cn.threewaters.qtyy.common.bean.PageBean;
import cn.threewaters.qtyy.common.bean.ResponseJson;
import cn.threewaters.qtyy.dic.one.queryparam.QueryKtkz;
import cn.threewaters.qtyy.dic.one.queryresult.ResultKtkz;
import cn.threewaters.qtyy.service.business.KtkzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "空调控制")
@Controller
@RequestMapping(value = "/ktkz")
public class KtkzController {
	@Autowired
	private KtkzService ktkzService;

	@ApiIgnore
	@ApiOperation(value = "空调控制仓房概览页面")
	@RequestMapping(value = "/cfgl/main", method = RequestMethod.GET)
	public ModelAndView cfglMain(ModelMap modelMap) {
		return new ModelAndView("business/ktkz/ktkzCfgl", modelMap);
	}

	@ApiIgnore
	@ApiOperation(value = "空调控制仓房详情页面")
	@RequestMapping(value = "/cfxq/main", method = RequestMethod.GET)
	public ModelAndView cfxqMain(ModelMap modelMap, String id) {
		modelMap.put("id", id);
		return new ModelAndView("business/ktkz/ktkzCfxq", modelMap);
	}

	@ApiOperation(value = "概览")
	@RequestMapping(value = "/GLlist", method = RequestMethod.GET)
	@ResponseBody
	public ResponseJson getGLList(QueryKtkz queryKtkz) throws Exception {
		List<ResultKtkz> ktkzGLs = ktkzService.queryKtkzGL(queryKtkz);
		return ResponseJson.builder().success(true).obj(ktkzGLs).build();
	}

	@ApiOperation(value = "详情")
	@RequestMapping(value = "/XQlist", method = RequestMethod.GET)
	@ResponseBody
	public ResponseJson getXQList(QueryKtkz queryKtkz) throws Exception {
		List<ResultKtkz> ktkzXQs = ktkzService.queryKtkzXQ(queryKtkz);
		return ResponseJson.builder().success(true).obj(ktkzXQs).build();
	}

	@ApiOperation(value = "列表")
	@RequestMapping(value = "/LBlist", method = RequestMethod.GET)
	@ResponseBody
	public ResponseJson getLBList(PageBean page, QueryKtkz queryKtkz) throws Exception {
		String jcsj = queryKtkz.getJcsj();
		if (jcsj != null && jcsj.indexOf(" - ") > 0) {
			queryKtkz.setChecktimebegin(jcsj.split(" - ")[0]);
			queryKtkz.setChecktimestop(jcsj.split(" - ")[1]);
		}
		Page<ResultKtkz> pageResult = new Page<ResultKtkz>();
		List<ResultKtkz> ktkzLBs = ktkzService.queryKtkzGL(queryKtkz);
		pageResult.setRecords(ktkzLBs);
		pageResult.setTotal(ktkzLBs.size());
		return ResponseJson.builder().success(true).obj(pageResult).build();
	}

}
